﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using HashMaster.Lib;

namespace HashMaster.Service
{
    // Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
    // NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
    // a single instance of the service to process all calls.	
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    // NOTE: If the service is renamed, remember to update the global.asax.cs file
    public class ClientService
    {

        /// <summary>
        /// 获取所有可用状态客户端
        /// </summary>
        /// <param name="clientName"></param>
        /// <param name="macAddress"></param>
        /// <returns></returns>
        [WebGet(UriTemplate = "")]
        public List<Client> Get()
        {
            //throw new NotImplementedException();
            return Utility.GetAllClients();
        }

        /// <summary>
        /// 客户端禁用并收回任务
        /// </summary>
        /// <param name="jobId"></param>
        [WebInvoke(UriTemplate = "/{clientName}/{macAddress}", Method = "DELETE")]
        [OperationContract]
        public void Delete(string clientName,string macAddress)
        {
            ClientSyncData clientData = new ClientSyncData();
            clientData.ClientName = clientName;
            clientData.MacAddress = macAddress;
            //clientData.ErrorCode= 
            Utility.RetrieveJob(clientData);
            //return clientData;
        }

    }
}
